package com.wisecoach.gatewayplus.transaction;

/**
 * {@code @author:} wisecoach
 * {@code @date:} 2023/9/30 下午3:50
 * {@code @version:} 1.0.0
 */


public class LocalTransactionContextProvider extends AbstractTransactionContextProvider {

    private static final String TXID_PREFIX = "TXID_";

    @Override
    protected TransactionStatus getTransaction(TransactionAttribute attribute) {
        TransactionContext oldTransaction = TransactionContextHolder.getContext();
        boolean isNewTransaction = oldTransaction == null;
        String id = TXID_PREFIX + Thread.currentThread().getId();
        return new DefaultTransactionStatus(id, attribute.getTransactionStrategy(), isNewTransaction);
    }
}
